// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "StateMachine.generated.h"

struct FInputActionValue;
class UState;

UENUM()
enum class EInputSignal : uint8
{
	MoveStart,
	Moving,
	MoveEnd,
	Jump,
	Attack,
	Dash,
};


UCLASS()
class PT001_API UStateMachine : public UObject
{
	GENERATED_BODY()

	UPROPERTY()
	UState* CurrentState;

	UPROPERTY()
	class ACharacter2D* Character;

	UPROPERTY()
	APlayerController* PlayerController;

	UPROPERTY()
	TMap<TSubclassOf<UState>, UState*> StateMap; 

	void CleanStates();
	
public:
	void Tick(float DeltaTime);
	
	void Init(APlayerController* Controller, ACharacter2D* Player);
	void SwitchState(UState* NewState);
	void SwitchState(const TSubclassOf<UState>& StateClass);
	void InputSignal(EInputSignal Signal, const FInputActionValue& Value);
	
	UStateMachine* AddState(UState* StateInstance);
	UStateMachine* AddState(const TSubclassOf<UState>& StateClass);
	
	UState* GetState(const TSubclassOf<UState>& StateClass) const;
};
